#include<bits/stdc++.h>
using namespace std;
int main(){
freopen("detect.in","r",stdin);
freopen("detect.out","w",stdout);
int t;
cin>>t;
long long p[t+1],q[t+1];
for(int k=1;k<=t;k++){
    long long n,m,L,V;
    long long ans=0;
    cin>>n>>m>>L>>V;
    long long l[n+1],v[n+1],a[n+1];
    for(int i=1;i<=n;i++){
        cin>>l[i]>>v[i]>>a[i];
    }
    long long c[m+1];
    for(long long i=1;i<=m;i++) cin>>c[i];
    for(long long i=1;i<=n;i++){
        if(l[i]<=c[m]&&v[i]>V) ans++;
    }
    p[k]=ans;
    q[k]=m-1;
}
for(int i=1;i<t;i++) cout<<p[i]<<" "<<q[i]<<endl;
cout<<p[t]<<" "<<q[t];
return 0;
}
